/*
    Heart of Gold engine management system
    Copyright (C) 2004 Heart of Gold development team

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * An abstract class that packages modules to be added to the HOG
 * and provides the interface to interact with it
 * @author Ryan Higgins and Greg Feigenson
 * @date 2004
 */
package com.heartOfGold.controller;

import java.util.Observer;
import java.util.Observable;
import javax.swing.JPanel;

import com.heartOfGold.model.Message;
import com.heartOfGold.model.megasquirtECU.MegasquirtMessenger;

public abstract class Component implements Observer {
    // TODO change variables to private and create accessor methods;
    protected String id; // ID for messages sent
    protected String panelLabel; // Main GUI Menu label
    protected JPanel panel; // The main panel for this component

    public void update(final Observable sender, final Object m) {
        // pre: sender is the messenger, m is the message
        // post: if the message's ID matches ours it's
        // for us and we call parseMessage()
        if (id.equals(((Message) m).getID())) {
            parseMessage((MegasquirtMessenger) sender, (Message) m);
        }
        return;
    }

    public abstract void parseMessage(MegasquirtMessenger sender, Message m);

    // for the extending class to make use of a received message

    // Getters - there are no symmetric setters because these
    // need to be hard wired by the extending class
    // TODO remedy that the following methods are not designed for extension
    public String getID() {
        return id;
    }

    public String getPanelLabel() {
        return panelLabel;
    }

    public JPanel getJPanel() {
        return panel;
    }
}
